﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BUSLayer;
using DAOLayer;

public partial class ThongTinFilm : System.Web.UI.Page
{
    public PhimBus film = new PhimBus();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int maso;
            object temp = (Request.QueryString.Get("MaPhim"));
            if (temp != null)
            {
                maso = Convert.ToInt32(temp);
            }
            else
                maso = 1;//lấy tạm 1 giá trị để demo

            LayThongTinPhim(maso);
            LayThongTinDaoDien(maso);
            LayDsDienVien(maso);
        }
    }

    private void LayThongTinPhim(int maso)
    {
        DataTable resFilm = film.LayThongTinPhim(maso);
        if (resFilm.Rows.Count > 0)
        {
            DataRow fRow = resFilm.Rows[0];
            tenLabel.Text = fRow["Ten"].ToString();
            gThieuLabel.Text = fRow["GioiThieu"].ToString();
            nsxLabel.Text = fRow["NSX"].ToString();
            qGiaLabel.Text = fRow["NuocSX"].ToString();
            dDaiLabel.Text = fRow["ThoiGian"].ToString();
            thLoaiLabel.Text = fRow["TheLoai"].ToString();
            namLabel.Text = fRow["NamSX"].ToString();
            trailerLabel.Text = fRow["Trailer"].ToString();
            string poster = @"images\Poster\";
            poster += fRow["Poster"].ToString();
            posterImage.ImageUrl = poster;
        }
    }

    private void LayThongTinDaoDien(int maso)
    {
        DataTable resDir = film.LayDsDaoDienTrongPhim(maso);
        if (resDir.Rows.Count > 0)
        {
            if (resDir.Rows.Count == 1)
            {
                DataRow directors = resDir.Rows[0];
                dDienLabel.Text = directors["HoTen"].ToString();
            }
            else
            {
                string dirs = "";
                DataRow directors;
                for (int j = 0; j < resDir.Rows.Count - 1; j++)
                {
                    directors = resDir.Rows[j];
                    dirs += directors["HoTen"].ToString() + ", ";
                }
                DataRow lastDir = resDir.Rows[resDir.Rows.Count - 1];
                dirs += lastDir["HoTen"].ToString();
                dDienLabel.Text = dirs;
            }
        }
    }

    private void LayDsDienVien(int maso)
    {
        DataTable resAct = film.LayDsDienVienTrongPhim(maso);
        if (resAct.Rows.Count > 0)
        {
            string dv = "";
            for (int i = 0; i < resAct.Rows.Count - 1; i++)
            {
                DataRow iAct = resAct.Rows[i];
                dv += iAct["HoTen"].ToString() + ", ";
            }
            DataRow lastAct = resAct.Rows[resAct.Rows.Count - 1];
            dv += lastAct["HoTen"].ToString();
            dvLabel.Text = dv;
        }
    }
}
